Skip to content

fix(studio): element picker style, data and text edits draw in a sealed preview - #8663

Merged
miguel-heygen merged 1 commit into
mainfrom
fix/sealed-picker-edits
Nov 24, 2026
Merged

miguel-heygen merged 1 commit into
mainfrom
fix/sealed-picker-edits

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

What

useElementPicker's setStyle, setDataAttr and setTextContent now draw on the picked element and save to source in a sealed preview, the same as in an unsealed one. Before this, all three looked up the element through iframe.contentDocument. A sealed frame does not expose it, so typing a style, a data attribute or text in the picker did nothing: nothing was drawn, the picker state did not change, and nothing was saved, with no error.

Why

A sealed preview must give exactly the same result as an unsealed one. The picker already shows a sealed pick (its styles come over the editing port, useElementPicker.ts showPicked), but its edits never reached the frame or the source.

Related work

Same port as #8149 (property panel style and attribute edits): editPreviewElement (packages/studio/src/player/lib/previewElements.ts:434), with queryPreviewElements and describePreviewElements to find the element and its source the way previewSelection.ts does (previewIdentity, previewElementSourceFile).

How

  • New hooks/elementPickerWrites.ts with writePicked(iframe, selector, write). For a readable frame it applies the live edit to the first selector match, as before, and returns the element's data-hf-id and source file. For a sealed frame it queries the first match's handle, describes it, draws the edit with editPreviewElement, and returns the same { hfId, ownFile } once the frame says it drew the edit (hfId from the description's attributes, ownFile from previewElementSourceFile).
  • The three setters in useElementPicker share one writePickedElement: draw, then update the picker state, then patch the source. That is the same order as before. syncToSource takes { hfId, ownFile } instead of the live element.
  • Text goes to the port as escaped markup (escapeHtmlText), which gives the same text node as textContent = text.
  • Limit, unchanged from the port's rule: the frame refuses a text edit on an element whose current content is more than text markup (editElement.ts refused). The sealed text setter then draws and saves nothing. Unsealed still overwrites. Lifting that rule is a separate decision about the port.

Test plan

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

packages/studio/src/hooks/elementPickerWrites.browser.test.ts opens the same preview in real Chrome, once same-origin and once sandboxed (HF_PARITY_MODE picks one). It applies a style, a data attribute and text with markup characters to .title, then a write to a selector with no match. It checks the frame's computed color, the attribute and the text, and that every write returns { hfId: "t1", ownFile: "index.html" } (null for the missing element). Both modes must give the same result.

Devbox: the named test passed 3 runs in a row (exit 0, 2 passed), the covering studio test passed, and studio tsc was clean.

fails without the fix: elementPickerWrites.browser.test.ts "the element picker's style, data and text edits draw in a sealed preview". With the sealed branch removed, so that only main's contentDocument path runs, the sealed case fails with expected { sources: [ null, null, …(2) ], …(1) } to deeply equal { sources: [ { …(2) }, …(3) ], …(1) } (exit 1, 1 failed, 1 passed): no write lands and nothing is drawn, which is what main does sealed. The unsealed case stays green.

Devbox gate at this head: Fallow audit clean, pre-push clean.

No visible change

No production code calls these three setters today:

  • In this repo, the only definitions and uses are inside packages/studio/src/hooks/useElementPicker.ts and the new test. A git grep for setStyle|setDataAttr|setTextContent over packages/ and docs/ finds no other caller. Studio's own panel edits go through onSetStyle and the DOM edit commits instead.
  • @hyperframes/studio exports useElementPicker (packages/studio/src/index.ts:188). Its one known consumer, the HyperFrames Desktop app, takes only pickedElement, isPickMode, enablePick, disablePick and clearPick from it, never the setters.

So no person sees row 48 on a screen yet. It reaches people only through an embedder that calls these setters on a sealed preview, and there it now draws and saves exactly as unsealed. The proof is the real-Chrome test above, which runs the real runtime in a sandboxed frame. The change is in .ts files only.

@github-actions

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 273 (base branch 271), smooth 58 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Newly passing (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)

  • seqscaletwice-scale-px-r0-nested-z100
  • seqscaletwice-scale-px-r0-root-z100

Quarantined, measured but not gated (0)

Unstable (1)

  • seqplainkeys-none-px-r0-nested-z100: tracking 0.07, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.07, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.07, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at 099e958.

  • fails without the fix: checked. With the sealed branch disabled, the sealed case fails with the message quoted in the body. At head it passes 2/2, the changed and covering test files pass 31/31, and tsc is clean.
  • Sealed and unsealed match: sealed edits now go through the editing port in the same order as unsealed: draw, then the picker state update, then the source patch with the same hfId/ownFile. The unsealed useElementPicker.test.ts passes unchanged.
  • File size: on the merge with current main, useElementPicker.ts is 529 lines and elementPickerWrites.ts is 52. The diff is .ts only, so the "No visible change" captures exemption applies.
  • No overlap: no files are shared with #8662 or #8668, and there's no dependency on either.

Nits, none blocking:

  1. A sealed text edit is refused when the element holds more than text, or when the value is over the length cap. Unsealed overwrites in those cases. The body says so.
  2. The sealed picker-state update lands after an await. If someone picks another element first, the edit lands on that element's state.
  3. Only writePicked is tested. The hook's sealed wiring (the state update and save after the promise) has no test.

Review by Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit 3ce07d4 Nov 24, 2026
127 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-picker-edits branch November 24, 2026 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants